<?php


/**
 * 汽车接口
 */
interface ICar
{
	/**
	 * 介绍方法
	 */
	public function intro();
}

/**
 * 卡车
 */
class Truck implements ICar
{
	public function intro()
	{
		echo '我是卡车。<br/>';
	}
}

/**
 * 客车
 */
class Bus implements ICar
{
	public function intro()
	{
		echo '我是客车。<br/>';
	}
}

/**
 * 汽车配件
 */
interface IAccessory
{
	public function intro();
}

/**
 * 卡车配件
 */
class TruckAccessory implements IAccessory
{
	public function intro()
	{
		echo '我是卡车配件。<br/>';
	}
}

/**
 * 客车配件
 */
class BusAccessory implements IAccessory
{
	public function intro()
	{
		echo '我是客车配件。<br/>';
	}
}

/**
 * 工厂
 */
interface IFactory
{
	public function craeteCar();
	public function createAccessory();
}

/**
 * 卡车工厂
 */
class TruckFactory implements IFactory
{
	public function craeteCar()
	{
		return new Truck();
	}
	
	public function createAccessory()
	{
		return new TruckAccessory();
	}
}

/**
 * 客车工厂
 */
class BusFactory implements IFactory
{
	public function craeteCar()
	{
		return new Bus();
	}
	
	public function createAccessory()
	{
		return new BusAccessory();
	}
}

class Client
{
	public static function main()
	{
		echo '同一个工厂创建不同类型的产品。<br/>';
		$factory = new TruckFactory();
		$truck = $factory->craeteCar();
		$truck->intro();
		$truckAccessory = $factory->createAccessory();
		$truckAccessory->intro();
	}
}

client::main();